package com.jyw.system.domain.dto;

import com.jyw.common.core.domain.model.WechatLoginBody;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.security.authentication.BadCredentialsException;

import javax.validation.constraints.NotBlank;

/**
 * @author 沈峻
 * @ClassName HospitalApiRequest
 * @Description 医院密钥实体
 * @Date 2023/9/5 15:34
 **/
@Data
public class HospitalApiRequest {
    @ApiModelProperty("医院公钥")
    @NotBlank(message = "医院公钥不能为空")
    private String serverKey;

    @ApiModelProperty("医院私钥")
    @NotBlank(message = "医院私钥不能为空")
    private String serverSecret;

    /**
     * 校验密钥是否正确
     * @param loginBody
     */
    public void validateSecret(WechatLoginBody loginBody) {
        if (getServerKey().equals(loginBody.getServerKey())&&getServerSecret().equals(loginBody.getServerSecret())) {
            return;
        }
        throw new BadCredentialsException("医院信息密钥错误");
    }
}
